package com.example.demo.controller;

import com.example.demo.pojo.Catrgoryicon;
import com.example.demo.pojo.Feedbackchuandi;
import com.example.demo.pojo.Swiperdata;
import com.example.demo.pojo.SwiperdataParamacc;
import com.example.demo.service.CategoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author yanglup
 * @create 2020-12-06 15:52
 */
@Controller
public class BackCategoryController {
    @Autowired
    CategoryService categoryService;

    /**查询的列表*/
    @RequestMapping("/Categoryicongonglist")
    public String Catrgoryicongonglist(Model model, HttpServletRequest request) {
        Integer pageNo=request.getParameter("pageNo")==null?1:Integer.valueOf(request.getParameter("pageNo"));
        PageInfo<Catrgoryicon> pageInfo=categoryService.Categoryicongonglist(pageNo,8);

        List<Catrgoryicon> Categoryicongonglist=pageInfo.getList();
        model.addAttribute("Categoryicongonglists",Categoryicongonglist);
        model.addAttribute("pages",pageInfo.getPages());
        model.addAttribute("pageNo",pageInfo.getPageNum());
        model.addAttribute("pageSize",pageInfo.getPageSize());

        Integer allnumber=categoryService.Catrgoryicongonglistnumber();
        model.addAttribute("allnumber",allnumber);
        return "Categoryicongonglist";
    }

//    /**查询的列表*/
//    @RequestMapping("/Categoryicongonglist")
//    public String Catrgoryicongonglist(Model model) {
//        List<Catrgoryicon> Categoryicongonglist = categoryService.Categoryicongonglist();
//        model.addAttribute("Categoryicongonglists",Categoryicongonglist);
//        Integer allnumber=categoryService.Catrgoryicongonglistnumber();
//        model.addAttribute("allnumber",allnumber);
//        return "Categoryicongonglist";
//    }



    /**跳转到修改页面*/
    @RequestMapping("/Categoryicongongupdate")
    public String Categoryicongongupdate(Model model,Integer cat_id){
        //通过id查询
        Catrgoryicon catrgoryicon=categoryService.Categoryicongongupdate(cat_id);
        model.addAttribute("catrgoryicon",catrgoryicon);
        return "Categoryicongongupdate";
    }
    /**修改2--保存数据跳回list*/
    @PostMapping("/Categoryicongonglisttijiao")//post
    public String Categoryicongonglisttijiao(Model model, Catrgoryicon catrgoryicon){
        //提交到数据库
        Integer cat_id=catrgoryicon.getCat_id();
        String cat_name=catrgoryicon.getCat_name();
        String cat_icon=catrgoryicon.getCat_icon();
        categoryService.Categoryicongonglisttijiao(cat_id,cat_name,cat_icon);
        return "redirect:/Categoryicongonglist";
    }



    /**通过名字搜索*/
    @RequestMapping("/Categoryicongonglistquery")
    public String Categoryicongonglistquery(String cat_name,Model model){
        List<Catrgoryicon> catrgoryicon=categoryService.Categoryicongonglistquery(cat_name);
        model.addAttribute("catrgoryicons",catrgoryicon);
        Integer allnumber=categoryService.Categoryicongonglistquerynumber(cat_name);
        model.addAttribute("allnumber",allnumber);
        return "Categoryicongonglistquery";
    }


}
